package cn.ezios.huo.system.biz.user;

import cn.dev33.satoken.stp.StpUtil;
import cn.ezios.huo.common.mvc.Ret;
import cn.ezios.huo.system.dao.domain.SysUser;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sys/user/info")
@RequiredArgsConstructor
public class InfoController {

    private final InfoService infoService;

    @GetMapping("get-menu-tree")
    public Ret getMenuTree() {
        String userId = getUserId();
        return Ret.ok(infoService.getMenuTree(userId));
    }

    @GetMapping("get-vue-routes")
    public Ret getVueRoutes(){
        String userId = getUserId();
        return Ret.ok(infoService.getUserVueRoute(userId));
    }

    private String getUserId() {
        SysUser sysUser = (SysUser)StpUtil.getSession().get("user");
        return sysUser.getUserId();
    }
}
